<template>
    <bi-form-item label="查询管理员">
        <bi-radio v-model="form.searchAdminUser" :option="searchAdminUserOption" :disabled="disabled"  ></bi-radio>
    </bi-form-item>
    <bi-form-item label="设置可查询分组" v-if="form.searchAdminUser=='custom'">
         <bi-list :data="form.searchUserGroupList"  v-slot="row"  type="border" dir="row" :disabled="disabled"  @add="addUserGroup" @del="delUserGroup"  >
            {{row.item.title}}
        </bi-list>
    </bi-form-item>
    <bi-form-item label="登录后跳转">
        <bi-input v-model="form.userLoginDirectLabel"  readonly :disabled="disabled" style="max-width: 250px;" >
            <template #after>
                <bi-button @click="selectLoginDirect" :disabled="disabled">设置</bi-button>
            </template>
        </bi-input>
    </bi-form-item>
</template>
<script>
import addUserGroupDialog from './add-user-group-dialog.vue';
import selectLoginDirectDialog from './select-login-direct-dialog.vue';
import powerExtendMixin from  '@@/admin/assets/js/powerExtendMixin.js';
export default {
    mixins:[powerExtendMixin],
    data(){
 
        let disabled = true;

        if (this.$user.super) disabled = false;
        if (this.userData && this.userData.searchAdminUser && this.userData.searchAdminUser=='all') disabled = false;

        let searchAdminUserOption = [
            {value:'all',disabled,label:'全部分组'},
            {value:'self',label:'用户所在组'},
            {value:'custom',label:'指定组'},
        ]

        let form = {
            searchAdminUser:'self',
            searchUserGroupList:[],
            userLoginDirect:'',
            userLoginDirectLabel:'',
        }

        
        
        return {
            searchAdminUserOption,
            form
        }
    },
    watch:{
        
    },
    methods:{
        addUserGroup(){

            let hasList = [];

            for(let i=0;i<this.form.searchUserGroupList.length;i++){
                hasList.push(this.form.searchUserGroupList[i].group_id);
            }

            this.$dialog({
                type:'vue',
                content:admin.createApp(addUserGroupDialog,{hasList}),
                callback:(re)=>{
                    if (re.group_id){
                        this.form.searchUserGroupList.push(re);
                    }
                }
            })
            },
            delUserGroup(index,item){
            this.$confirm('确定要删除['+item.title+']吗',(re)=>{
                if (re){
                    this.form.searchUserGroupList.splice(index,1);
                }
            });
        },
        selectLoginDirect(){
            this.$dialog({
                type:'vue',
                content:admin.createApp(selectLoginDirectDialog),
                callback:(re)=>{
                    this.form.userLoginDirect = re.value;
                    this.form.userLoginDirectLabel = re.label;
                }
            })
        }
    },
    
}
</script>